package data;

/**
 * An exception indicating that there was an error when interacting with the
 * database
 * 
 * @author Kelsey
 */
public class DBInterfaceError extends Exception {

	/**
	 * Not used.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * A enum of the possible errors
	 * 
	 * @author Pooja
	 */
	public enum Error {
		ACCOUNT_CREATION_ACCOUNT_ALREADY_EXISTS(
				"An account with this username already exists."), ACCOUNT_CREATION_INVALID_NAME(
				"The username chosen is invalid."), ACCOUNT_CREATION_INVALID_PASSWORD(
				"The password chosen is invalid."), ACCOUNT_CREATION_DATABASE_ERROR(
				"The account could not be created in the database."), LOGIN_ACCOUNT_DOES_NOT_EXIST(
				"There is no account by this username"), LOGIN_INCORRECT_PASSWORD(
				"The given password is incorrect."), LOGIN_ACCOUNT_LOCKED(
				"This account has been locked. Contact an admin for more information."), CONNECTION_ERROR(
				"Could not properly connect to the database");

		/** message describing the error */
		private String message;

		/**
		 * This is a constructor for the enum
		 */
		private Error() {
			this("");
		}

		/**
		 * A constructor that takes in a string
		 * 
		 * @param message
		 */
		private Error(String message) {
			this.message = message;
		}

		/**
		 * Gets the string that is the error
		 * 
		 * @return
		 */
		public String getMessage() {
			return this.message;
		}
	}

	/** the error being represented */
	public Error err;

	/**
	 * A constructor for the DB error that takes in a DBInterface.Error and sets
	 * its err to it
	 * 
	 * @param err
	 */
	public DBInterfaceError(Error err) {
		this.err = err;
	}

	/**
	 * Gets the releavant message
	 */
	@Override
	public String getMessage() {
		return this.err.getMessage();
	}
}
